﻿using A2.ERP.BLL;
using A2.ERP.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Mvc;

namespace A2.ERP.UI.Filters
{
    public class AuthFilterAttribute : AuthorizeAttribute
    {
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            var request = filterContext.HttpContext.Request;
            var response = filterContext.HttpContext.Response;
            string uid = request.Cookies["uid"] == null ? "" : request.Cookies["uid"].Value;

            string url = request.RawUrl.ToLower();
            string[] skipValidate = new[] { "login", "home" };
            if (skipValidate.Any(i => url.Contains(i)))
                return;
            if (string.IsNullOrEmpty(uid))
                response.Redirect("/login");

            response.Write(url);
        }
    }
}